package com.eight.course.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eight.common.pojo.EduCourse;
import com.eight.common.pojo.TbCheckCourse;
import com.eight.course.dao.CheckCourseDao;
import com.eight.course.dao.CourseDao;
import com.eight.course.service.CheckCourseService;
import com.eight.course.vo.CourseVo;
import com.eight.course.vo.SubjectVo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * @program: qy8-education
 * @description:
 * @author: 张亚祥
 * @create: 2023-05-29 21:33
 **/
@Service
public class CheckCourseServiceImpl implements CheckCourseService {
    @Resource
    private CheckCourseDao checkCourseDao;
    @Resource
    private CourseDao courseDao;
    @Override
    public Page<EduCourse> findCherckCourse(Integer currentSize, Integer pageSize, CourseVo courseVo) {

        Page<EduCourse> page = new Page<>(currentSize, pageSize);
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        if (StringUtils.hasText(courseVo.getTitle())) {
            wrapper.like("title", courseVo.getTitle());
        }
        if (StringUtils.hasText(courseVo.getStatus())) {
            wrapper.eq("status", courseVo.getStatus());
        }
        Page<EduCourse> cherckCourse = courseDao.findCherckCourse(page, wrapper);
        return cherckCourse;
    }

    @Override
    public int updateCheck(TbCheckCourse tbCheckCourse) {
            tbCheckCourse.setCourseCheckId(tbCheckCourse.getCourseCheckId());
            tbCheckCourse.setCheckStatus(tbCheckCourse.getCheckStatus());
            int byId = checkCourseDao.updateById(tbCheckCourse);
            return byId;
    }

}
